/*

Summary:
Use to determinate the string's composition.

Remark:
None.

Version:
0.0.1

LastUpdatedDate:
2012-09-20

CreatedDate:
2012-09-20

*/


#pragma once

#include <string>
#include "CString.h"


namespace Zaf {
namespace String {
namespace __Internal {


template<typename CharType>
bool __HasPrefix(const CharType* str, const CharType* prefix, int prefixLen, bool ignoreCase) {
	return (ignoreCase == true ? StrNICmp(str, prefix, prefixLen) : StrNCmp(str, prefix, prefixLen)) == 0;
}



template<typename CharType>
bool __HasSuffix(const CharType* str, int strLen, const CharType* suffix, int suffixLen, bool ignoreCase) {

	if (strLen < suffixLen) {
		return false;
	}

	const CharType* beginPos = str + strLen - suffixLen;

	return (ignoreCase == true ? StrNICmp(beginPos, suffix, suffixLen) : StrNCmp(beginPos, suffix, suffixLen)) == 0;
}



}  // __Internal



template<typename CharType>
bool HasPrefix(const std::basic_string<CharType>& str, const std::basic_string<CharType>& prefix, bool ignoreCase = false) {
	return __Internal::__HasPrefix(str.c_str(), prefix.data(), prefix.length(), ignoreCase);
}

template<typename CharType>
bool HasPrefix(const std::basic_string<CharType>& str, const CharType* prefix, bool ignoreCase = false) {
	return __Internal::__HasPrefix(str.c_str(), prefix, StrLen(prefix), ignoreCase);
}

template<typename CharType>
bool HasPrefix(const CharType* str, const std::basic_string<CharType>& prefix, bool ignoreCase = false) {
	return __Internal::__HasPrefix(str, prefix.data(), prefix.length(), ignoreCase);
}

template<typename CharType>
bool HasPrefix(const CharType* str, const CharType* prefix, bool ignoreCase = false) {
	return __Internal::__HasPrefix(str, prefix, StrLen(prefix), ignoreCase);
}



template<typename CharType>
bool HasSuffix(const std::basic_string<CharType>& str, const std::basic_string<CharType>& suffix, bool ignoreCase = false) {
	return __Internal::__HasSuffix(str.c_str(), str.length(), suffix.data(), suffix.length(), ignoreCase);
}

template<typename CharType>
bool HasSuffix(const std::basic_string<CharType>& str, const CharType* suffix, bool ignoreCase = false) {
	return __Internal::__HasSuffix(str.c_str(), str.length(), suffix, StrLen(suffix), ignoreCase);
}

template<typename CharType>
bool HasSuffix(const CharType* str, const std::basic_string<CharType>& suffix, bool ignoreCase = false) {
	return __Internal::__HasSuffix(str, StrLen(str), suffix.data(), suffix.length(), ignoreCase);
}

template<typename CharType>
bool HasSuffix(const CharType* str, const CharType* suffix, bool ignoreCase = false) {
	return __Internal::__HasSuffix(str, StrLen(str), suffix, StrLen(suffix), ignoreCase);
}



}
}